//add  by  xujun   2017-07-29
var pathName = window.document.location.pathname;  
//获取带"/"的项目名，如：/proj  
var ctx = pathName.substring(0, pathName.substr(1).indexOf('/')+1); 

$(function() {
	var types=$("#types").val();
	if(types==1){
		document.getElementById("type").selectedIndex =1;
	}
	if(types==2){
		document.getElementById("type").selectedIndex =2;
	}
	if(types==3){
		document.getElementById("type").selectedIndex =3;
	}
	
	jQuery.ajax({
		url:ctx+"/role/getRoleType",
		type: "POST",
		async: "false",
		timeout: 30000,
		success: function(ret){
			var htrm="";
			for (var k = 0, length = ret.length; k < length; k++) {
				htrm=htrm+"<option value="+ret[k].ddvCode+">"+ret[k].value+"</option>"
				}
			$("#type").html(htrm);
			$("#type").val(types);
		},
		error: function() {
			parent.$.messager.alert('错误', "数据异常，添加失败", 'error');
			//请求父页面关闭
			add_close();
		}
	});	
});
//编辑
function editRole(){
	var roId=$("#roId").val();
	var toName=$("#toName").val();
	var type=$("#type").val();
	var notes=$("#note").val();
	if(""==toName){
		parent.$.messager.alert('提示',"请输入名称！", 'info');
		return false;
	}
	jQuery.ajax({
		//ajax请求页面
		url:ctx+"/role/updateRole",
		type: "POST",
		async: "false",
		timeout: 30000,
		data: {"roId":roId,"toName":toName,"type":type,"notes":notes},
		success: function(ret) {
			if(ret.state==-1){
				parent.$.messager.confirm('询问', '您还未登录或登录超时！请重新登录？', function(b) {
					if (b) {
						parent.window.location.href='${ctx}/login';
					}
				});
			}
			if(ret.state==2){
				parent.$.messager.alert('错误', "角色名称已存在", 'error');
				//请求父页面关闭				
			}
			if(ret.state==0){
				parent.show("编辑成功","提示");
				//请求父页面关闭
				edit_close();
			}
		},
		error: function() {
			parent.$.messager.alert('错误', "数据异常，添加失败", 'error');
			//请求父页面关闭
			edit_close();
		}
	});	
}
